Skip to content

Normalize relative working directories in glob searches - #1725

Open
VIOLETee0 wants to merge 1 commit into
CodebuffAI:mainfrom
VIOLETee0:fix/glob-relative-cwd
Open

VIOLETee0 wants to merge 1 commit into
CodebuffAI:mainfrom
VIOLETee0:fix/glob-relative-cwd

Conversation

@VIOLETee0

Copy link
Copy Markdown

A glob search with cwd: "." reports zero files even when the project contains matches. Likewise, ./src and src/../src fail because the SDK compares the raw cwd with project-relative file paths.

Normalize cwd before filtering, treat the project-root dot path as the full project, and convert native path separators to the file tree's forward slashes. Returned paths and pattern matching retain their project-relative semantics.

One regression scans a real temporary project and checks the file sets for equivalent relative directories, including the host's native separator. On unmodified main (1279f1463) it fails with 0 files instead of 4; with the patch it passes.

Validation on Windows, Bun 1.3.14:

  • New regression and existing runtime glob handlers: 12 passed.
  • The 5 existing SDK glob fixture tests fail identically on unmodified main and the patched tree in this Windows environment.
  • SDK TypeScript, frozen-lockfile install, SDK build, Windows binary build, version and official smoke passed.
  • Prettier and diff checks passed; ESLint has 0 errors and 4 resolver-configuration warnings.

No authenticated model/TUI session or Linux/macOS build was run.

@codebuff-team

Copy link
Copy Markdown
Contributor

Good catch and a clean fix. The root bug is real: the old prefix-matching logic in glob.ts never special-cased cwd === '.' (so it filtered against './' and dropped every file), and it never normalized the cwd string, so ./src and src/../src didn't match the project-relative /-separated paths produced by flattenTree. Using path.normalize + converting path.sep to / + special-casing '.' as "no filter" is the right, small fix for this.

The new test in glob-cwd.test.ts is appropriately scoped — it builds a real temp project, writes nested files, and checks several equivalent relative cwd spellings including the native separator case (path.join('src','nested','..')). That's exactly the kind of regression coverage this fix needs, and the PR description is honest about pre-existing unrelated SDK fixture failures on your Windows environment (good diligence, not hiding anything).

Two things worth double-checking before this lands:

  1. Behavior for an absolute cwd (outside the project root) isn't addressed — probably fine since that's out of scope for this bug, but worth a one-line comment confirming it's an explicit non-goal.
  2. path.normalize uses the OS-native separator semantics; on Windows this correctly produces backslash-normalized paths before you convert to /, but it'd be good to confirm this behaves identically if cwd is ever constructed with mixed separators from a config file rather than a CLI arg.

Overall this is a focused, well-tested fix in the right file. Worth porting as-is, pending a maintainer glance at the absolute-path edge case.

@codebuff-team codebuff-team added bot:triaged Classified by the community triage bot pr:port-candidate Worth porting into the private source tree labels Nov 26, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:triaged Classified by the community triage bot pr:port-candidate Worth porting into the private source tree

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants